package org.jivesoftware.smackx;

import java.util.Hashtable;
import java.util.Map;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.packet.DefaultPrivateData;
import org.jivesoftware.smackx.packet.PrivateData;
import org.jivesoftware.smackx.provider.PrivateDataProvider;
import org.xmlpull.v1.XmlPullParser;

public class PrivateDataManager
{
  private static Map<String, PrivateDataProvider> privateDataProviders = new Hashtable();
  private Connection connection;
  private String user;

  public static PrivateDataProvider getPrivateDataProvider(String paramString1, String paramString2)
  {
    String str = getProviderKey(paramString1, paramString2);
    return (PrivateDataProvider)privateDataProviders.get(str);
  }

  public static void addPrivateDataProvider(String paramString1, String paramString2, PrivateDataProvider paramPrivateDataProvider)
  {
    String str = getProviderKey(paramString1, paramString2);
    privateDataProviders.put(str, paramPrivateDataProvider);
  }

  public static void removePrivateDataProvider(String paramString1, String paramString2)
  {
    String str = getProviderKey(paramString1, paramString2);
    privateDataProviders.remove(str);
  }

  public PrivateDataManager(Connection paramConnection)
  {
    if (!paramConnection.isAuthenticated())
      throw new IllegalStateException("Must be logged in to XMPP server.");
    this.connection = paramConnection;
  }

  public PrivateDataManager(Connection paramConnection, String paramString)
  {
    if (!paramConnection.isAuthenticated())
      throw new IllegalStateException("Must be logged in to XMPP server.");
    this.connection = paramConnection;
    this.user = paramString;
  }

  public PrivateData getPrivateData(final String paramString1, final String paramString2)
    throws XMPPException
  {
    IQ local1 = new IQ()
    {
      public String getChildElementXML()
      {
        StringBuilder localStringBuilder = new StringBuilder();
        localStringBuilder.append("<query xmlns=\"jabber:iq:private\">");
        localStringBuilder.append("<").append(paramString1).append(" xmlns=\"").append(paramString2).append("\"/>");
        localStringBuilder.append("</query>");
        return localStringBuilder.toString();
      }
    };
    local1.setType(IQ.Type.GET);
    if (this.user != null)
      local1.setTo(this.user);
    String str = local1.getPacketID();
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(str));
    this.connection.sendPacket(local1);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from the server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
    return ((PrivateDataResult)localIQ).getPrivateData();
  }

  public void setPrivateData(final PrivateData paramPrivateData)
    throws XMPPException
  {
    IQ local2 = new IQ()
    {
      public String getChildElementXML()
      {
        StringBuilder localStringBuilder = new StringBuilder();
        localStringBuilder.append("<query xmlns=\"jabber:iq:private\">");
        localStringBuilder.append(paramPrivateData.toXML());
        localStringBuilder.append("</query>");
        return localStringBuilder.toString();
      }
    };
    local2.setType(IQ.Type.SET);
    if (this.user != null)
      local2.setTo(this.user);
    String str = local2.getPacketID();
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(str));
    this.connection.sendPacket(local2);
    IQ localIQ = (IQ)localPacketCollector.nextResult(5000L);
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from the server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
  }

  private static String getProviderKey(String paramString1, String paramString2)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<").append(paramString1).append("/><").append(paramString2).append("/>");
    return localStringBuilder.toString();
  }

  public static class PrivateDataIQProvider
    implements IQProvider
  {
    public IQ parseIQ(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      Object localObject = null;
      int i = 0;
      while (i == 0)
      {
        int j = paramXmlPullParser.next();
        if (j == 2)
        {
          String str1 = paramXmlPullParser.getName();
          String str2 = paramXmlPullParser.getNamespace();
          PrivateDataProvider localPrivateDataProvider = PrivateDataManager.getPrivateDataProvider(str1, str2);
          if (localPrivateDataProvider != null)
          {
            localObject = localPrivateDataProvider.parsePrivateData(paramXmlPullParser);
          }
          else
          {
            DefaultPrivateData localDefaultPrivateData = new DefaultPrivateData(str1, str2);
            int k = 0;
            while (k == 0)
            {
              int m = paramXmlPullParser.next();
              if (m == 2)
              {
                String str3 = paramXmlPullParser.getName();
                if (paramXmlPullParser.isEmptyElementTag())
                {
                  localDefaultPrivateData.setValue(str3, "");
                }
                else
                {
                  m = paramXmlPullParser.next();
                  if (m == 4)
                  {
                    String str4 = paramXmlPullParser.getText();
                    localDefaultPrivateData.setValue(str3, str4);
                  }
                }
              }
              else if ((m == 3) && (paramXmlPullParser.getName().equals(str1)))
              {
                k = 1;
              }
            }
            localObject = localDefaultPrivateData;
          }
        }
        else if ((j == 3) && (paramXmlPullParser.getName().equals("query")))
        {
          i = 1;
        }
      }
      return new PrivateDataManager.PrivateDataResult((PrivateData)localObject);
    }
  }

  private static class PrivateDataResult extends IQ
  {
    private PrivateData privateData;

    PrivateDataResult(PrivateData paramPrivateData)
    {
      this.privateData = paramPrivateData;
    }

    public PrivateData getPrivateData()
    {
      return this.privateData;
    }

    public String getChildElementXML()
    {
      StringBuilder localStringBuilder = new StringBuilder();
      localStringBuilder.append("<query xmlns=\"jabber:iq:private\">");
      if (this.privateData != null)
        this.privateData.toXML();
      localStringBuilder.append("</query>");
      return localStringBuilder.toString();
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smackx.PrivateDataManager
 * JD-Core Version:    0.6.1
 */